Occurs after editing is completed in a cell, but before data is moved from the cell to the DataGrid control's copy buffer.
Syntax
Private Sub object_BeforeColUpdate ([ index As Integer,] colindex As Integer, oldvalue As Variant, cancel As Integer)
The BeforeColUpdate event syntax has these parts:
Part | Description |
object | An object expression that evaluates to an object in the Applies To list. |
index | An integer that identifies a control if it is in a control array. |
colindex | An integer that identifies the column. |
oldvalue | A value that contains the value contained in the cell prior to the change. |
cancel | A Boolean expression expression that specifies whether the change occurs, as described in Settings. |
Settings
The settings for cancel are:
Setting | Description |
True | Cancels the change, restores cell to oldvalue, and restores focus to the control. |
False | (Default) Continues with change and permits change of focus. |
Remarks
The data specified by the oldvalue argument moves from the cell to the control's copy buffer when a user completes editing within a cell, as when tabbing to another column in the same row, pressing ENTER, or changing focus away from the cell. Before the data has been moved from the cell into the control's copy buffer, the BeforeColUpdate event is triggered. This event gives your application an opportunity to check the individual grid cells before they are committed to the control's copy buffer.
If your event procedures set the cancel argument to True, the previous value is restored in the cell and focus remains on the control and the AfterColUpdate event is not triggered.
To restore oldvalue in the cell and permit the user to move focus off of the cell, set cancel to False and set the cell to oldvalue as follows:
Cancel = False
DataGrid1.Columns(ColIndex).Value = OldValue
The AfterColUpdate event occurs after the BeforeColUpdate event.
By setting the cancel argument to True, the user can not move the focus from the control until the application determines that the data can be safely moved back to the control's copy buffer.